<?php $__env->startSection('css'); ?>
    <style>
        .layer-go-back{
            display:none;
        }
    </style>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('title'); ?>
    <li class="cur">
        <span>会员充值设置</span>
    </li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

    <input type="hidden" name="function_id" id="function_id" value="<?php echo e(isset($function_id) ? $function_id : ''); ?>">
    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span> 是否开启余额充值：</label>
        <div class="col-sm-6">

            <div class="layui-form">
                <input type="radio" name="balance_recharge_open"  value="1"  title="是" class="is_open" lay-filter="filter" <?php if( isset($configure['balance_recharge_open']) && $configure['balance_recharge_open'] == 1): ?> checked <?php endif; ?>>
                <input type="radio" name="balance_recharge_open"  value="0"  title="否" class="is_open"  lay-filter="filter" <?php if( !isset($configure['balance_recharge_open']) || $configure['balance_recharge_open'] == 0): ?> checked <?php endif; ?>>
            </div>

        </div>
    </div>

    <div id="change_balance_recharge_open" <?php if( isset($configure['balance_recharge_open']) && $configure['balance_recharge_open'] == 0): ?> style="display: none" <?php endif; ?> >
    <div class="form-group" id="adjust_amount" >
        <label class="col-sm-3 control-label"><span class="red pr5">*</span> 是否可调整充值金额：</label>
        <div class="col-sm-6">

            <div class="layui-form">
                <input type="radio" name="adjust_amount"  value="1"  title="是"  <?php if( isset($configure['adjust_amount']) && $configure['adjust_amount'] == 1): ?> checked <?php endif; ?>>
                <input type="radio" name="adjust_amount"  value="0"  title="否"  <?php if( !isset($configure['adjust_amount']) || $configure['adjust_amount'] == 0): ?> checked <?php endif; ?>>
            </div>

        </div>
    </div>

    <div class="form-group"  id="single">
        <label class="col-sm-3 control-label" for="single_limit"><span class="red pr5">*</span> 单笔限额：</label>
        <div class="col-sm-5 form-inline">
            <input type="text" placeholder="单笔限额" style="width:130px;"  name="single_limit" id="single_limit"  class="form-control" value="<?php echo e(isset($configure['single_limit']) ? $configure['single_limit'] : ''); ?>">&nbsp;&nbsp;
            <span style="color:#999;">默认是0，0表示无限制</span>
        </div>
    </div>

    <div class="form-group"   id="daily">
        <label for="title" class="col-sm-3 control-label"><span class="red mr5">*</span> 单日限额：</label>
        <div class="col-sm-5 form-inline">
            <input type="text" class="form-control" style="width:130px;"  id="daily_limit" name="daily_limit"  placeholder="单日限额" value="<?php echo e(isset($configure['daily_limit']) ? $configure['daily_limit'] : ''); ?>">&nbsp;&nbsp;
            <span style="color:#999;">默认是0，0表示无限制</span>
        </div>
    </div>

    <div class="form-group"  id="rechange_amount">
        <label  class="col-sm-3 control-label"><span class="red mr5">*</span> 充值金额：</label>
        <div class="col-sm-8">
            <div class="panel panel-default" style="width:50%;">
                <div class="panel-heading">选中一行并拖动鼠标，进行排列</div>
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th style="text-align:left;">充值金额</th>
                        <th style="text-align:center;">操作</th>
                    </tr>
                    </thead>
                    <tbody id="sortable_tr">
                    </tbody>
                </table>
                <div class="panel-footer">
                    <input type="button"  value="添加金额" onclick="func.addTr();" class="btn btn-success" >
                </div>
            </div>
        </div>
    </div>

    <div class="form-group"  id="pay">
        <label  class="col-sm-3 control-label"><span class="red mr5">*</span> 充值支付方式：</label>
        <div class="col-sm-9 form-inline">
            <div class="layui-form">

                <input type="checkbox"  name="weixin_pay"  value="微信支付" title="微信支付" <?php if( isset($configure['pay_method']['weixin_pay']) && $configure['pay_method']['weixin_pay'] == "微信支付"): ?> checked <?php endif; ?>>

                <input type="checkbox"  name="alipay"  value="支付宝支付" title="支付宝支付" <?php if( isset($configure['pay_method']['alipay']) && $configure['pay_method']['alipay'] == "支付宝支付"): ?> checked <?php endif; ?>>

                <input type="checkbox"  name="union_pay"  value="银联支付" title="银联支付" <?php if( isset($configure['pay_method']['union_pay']) && $configure['pay_method']['union_pay'] == "银联支付"): ?> checked <?php endif; ?>>

                <input type="checkbox"  name="baidu_wallet"  value="百度钱包"  title="百度钱包" <?php if( isset($configure['pay_method']['baidu_wallet']) && $configure['pay_method']['baidu_wallet'] == "百度钱包"): ?> checked <?php endif; ?>>

                <input type="checkbox"  name="card_payment"  value="充值卡支付"  title="充值卡支付" <?php if( isset($configure['pay_method']['card_payment']) && $configure['pay_method']['card_payment'] == "充值卡支付"): ?> checked <?php endif; ?>>
            </div>
        </div>
    </div>

    <div class="form-group"   id="rechange_info">
        <label for="title" class="col-sm-3 control-label"> 充值说明：</label>
        <div class="col-sm-3">
            <textarea id="explain" rows="3" name="explain" class="form-control"><?php echo isset($configure['explain']) ? $configure['explain'] : ''; ?></textarea>
        </div>
    </div>

    <div class="form-group" >
        <label  class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>是否开启充值卡：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio"  class="is_recharge_card" name="is_recharge_card" lay-filter="is_recharge_card" value="0"  title="否" <?php if( !isset($configure['is_recharge_card']) || $configure['is_recharge_card'] == 0 ): ?> checked <?php endif; ?>>
                <input type="radio"  class="is_recharge_card" name="is_recharge_card" lay-filter="is_recharge_card" value="1"  title="是" <?php if( isset($configure['is_recharge_card']) && $configure['is_recharge_card'] == 1 ): ?> checked <?php endif; ?>>
            </div>
        </div>
    </div>

    <div class="form-group" id="card_name" <?php if( !isset($configure['is_recharge_card']) || $configure['is_recharge_card'] == 0 ): ?> style="display: none" <?php endif; ?>>
        <label class="col-sm-3 control-label" ><span class="red pr5">*&nbsp;</span> 充值卡名称：</label>
        <div class="col-sm-4">
            <input type="text"  name="card_name"  class="form-control card_name" value="<?php if( isset($configure['card_name']) && $configure['card_name'] ): ?> <?php echo e($configure['card_name']); ?> <?php else: ?> 充值卡 <?php endif; ?>">
        </div>
    </div>

    <div class="form-group" id="consume_type" <?php if( !isset($configure['is_recharge_card']) || $configure['is_recharge_card'] == 0 ): ?> style="display: none" <?php endif; ?>>
        <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>核销类型：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="consume_type" lay-filter="is_pay" class="consume_type" value="1" title="线上" checked>
                <input type="radio" name="consume_type" lay-filter="is_pay" class="consume_type"  value="2" title="线下" <?php if( isset($configure['consume_type']) && $configure['consume_type'] == 2): ?> checked <?php endif; ?>>
            </div>
        </div>
    </div>

    <div class="form-group" id="is_full_pay" <?php if( !isset($configure['consume_type']) || $configure['consume_type'] != 2 || !isset($configure['is_recharge_card']) || $configure['is_recharge_card'] != 1 ): ?> style="display: none" <?php endif; ?>>
        <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>充值类型：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="is_full_pay" class="is_full_pay" value="1" title="全额充" checked>
                <input type="radio" name="is_full_pay" class="is_full_pay"  value="2" title="部分充" <?php if( isset($configure['is_full_pay']) && $configure['is_full_pay'] == 2): ?> checked <?php endif; ?>>
            </div>
        </div>
    </div>

    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <input type="button"  value="保存" onclick="func.edit();" class="btn btn-success" >
        </div>
    </div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <script>
        layui.use(['form'], function() {
            var form = layui.form();

            //监听单选框
            form.on('radio(filter)',function(data){
                if ( data.value == 1 ) {
                    $('#change_balance_recharge_open').show();
                } else {
                    $('#change_balance_recharge_open').hide();
                }

            });

            form.on('radio(is_recharge_card)',function(data){
                if ( data.value == 1 ) {
                    $('#card_name,#consume_type').show();
                } else {
                    $('#card_name,#consume_type').hide();
                }
                var consume_type = $('.consume_type:checked').val();
                if ( consume_type == 2 && data.value == 1) {
                    $('#is_full_pay').show();
                } else {
                    $('#is_full_pay').hide();
                }

            });

            form.on('radio(is_pay)',function(data){
                if ( data.value == 2 ) {
                    $('#is_full_pay').show();
                } else {
                    $('#is_full_pay').hide();
                }

            });

        });

        $(function(){
            var configure_array = 0 ;
            if ( !E.isEmpty(<?php echo isset($configure_json) ? $configure_json : 0; ?>) ) {
                var content_str = '<?php echo isset($configure_json) ? $configure_json : 0; ?>'.replace(/\n/g, '<br>');
                configure_array = eval( '(' + content_str  + ')' );
            }

            if ( configure_array ) {

                var html = '' ;
                var conut= 1;
                //已存在配置
                if( !E.isEmpty( configure_array['configure']['amount'] ) ) {
                    $.each( configure_array['configure']['amount'] , function( k ,v ) {
                        if(!E.isEmpty(v )){
                            html +='<tr  class="amount" name="'+conut+'" id="tr'+conut+'">';
                            html +='<td style="text-align:center;"><input  type="text" class="form-control"  name="item_name" value="'+ v +'"></td>';
                            html +='<td  class="cancel" style="text-align:center;" ><span class="btn btn-danger" onclick="func.del('+conut+');">删除</span> </td>';
                        }
                        html +='</tr>';
                        conut++;
                    }) ;
                }else{
                    html +='<tr  class="amount" name="1" id="tr1">';
                    html +='<td style="text-align:left;"><input  type="text" class="form-control"  name="item_name" value=""></td>';
                    html +='<td  class="cancel" style="text-align:center;"><span class="btn btn-danger"  onclick="func.del(1)">删除</span> </td>';
                    html +='</tr>';
                }

                //向表格中插入行
                $('#sortable_tr').append( html ) ;
                init();
            }

        });


        var func = {

            addTr:function(){

                var column_count = 0;

                $('.amount').each( function (k,v) {
                    var item_name = $(v).find('input[name=item_name]').val() ;
                    var msg = '';
                    if(item_name==0){
                        msg +='第'+(k+1)+'行充值金额不能为0</br>';
                    }
                    if(!E.isNum(item_name)){
                        msg +='第'+(k+1)+'行充值金额必须为数字';
                    }

                    if( msg ) {
                        column_count++;
                        layer.alert( msg , { icon:2 } ) ;
                        return false ;
                    }
                }) ;

                if(column_count <= 0){
                    var lengthTr = $('.amount').length+1;
                    var html = '' ;
                    html +='<tr  class="amount" name="'+lengthTr+'" id="tr'+lengthTr+'">';
                    html +='<td style="text-align:left;"><input  type="text" class="form-control"  name="item_name" value=""></td>';
                    html +='<td  class="cancel" style="text-align:center;" ><span class="btn btn-danger"  onclick="func.del('+lengthTr+')">删除</span> </td>';
                    html +='</tr>';
                    //向表格中插入行
                    $('#sortable_tr').append( html ) ;
                    init();
                }
            },



            del:function(k){
                layer.confirm('您确认要删除该选项吗？',{icon:3},function(){
                    $('#tr'+k).remove();
                    layer.closeAll();
                });
            },

            //保存
            edit:function(){

                var amount =[];
                $('.amount').each(function(){
                    var item_name = $(this).find('input[name=item_name]').val() ;
                    if(item_name){
                        amount.push(item_name);
                    }
                });

                //表单数据
                var balance_recharge_open = $('input[name="balance_recharge_open"]:checked').val();
                var adjust_amount = $('input[name="adjust_amount"]:checked').val();
                var function_id = $('#function_id').val();
                var single_limit = $('#single_limit').val();
                var daily_limit = $('#daily_limit').val();
                var explain = $('#explain').val();
                var is_recharge_card = $('.is_recharge_card:checked').val();
                var card_name = $('.card_name').val();
                var consume_type = $('.consume_type:checked').val();
                var is_full_pay = $('.is_full_pay:checked').val();
                var pay_method = { };

                $('#pay').find('input:checked').each(function(){
                    pay_method[this.name]=this.value;
                });

                //组装ajax数据
                var configure ={ };

                configure.balance_recharge_open = balance_recharge_open;

                if(balance_recharge_open == 1){
                    configure.single_limit = single_limit;
                    configure.daily_limit = daily_limit;
                    configure.amount = amount;
                    configure.pay_method = pay_method;
                    configure.explain = explain;
                    configure.adjust_amount = adjust_amount;
                    configure.is_recharge_card = is_recharge_card;
                }

                configure.function_id =function_id;

                var msg ='';

                if(balance_recharge_open == 1){
                    if(E.isEmpty(single_limit)){
                        msg+='请输入单笔限额</br>';
                    }

                    if(E.isEmpty(daily_limit)){
                        msg+='请输入单日限额</br>';
                    }

                    if((configure.amount).length==0){
                        msg +='请输入充值金额</br>';
                    }

                    if($.isEmptyObject(pay_method )){
                        msg +='请选择充值支付方式</br>';
                    }

                    if ( is_recharge_card == 1 ) {



                        configure.consume_type = consume_type;
                        configure.card_name = card_name;

                        if(E.isEmpty(card_name)) {
                            msg +='充值卡名称不能为空</br>';
                        }

                        if ( consume_type == 1 ) {
                            configure.is_full_pay = '';
                        } else {
                            configure.is_full_pay = is_full_pay;
                        }

                    }


                }

                if (msg) {
                    layer.alert(msg,{icon:2});
                    return false;
                }

                var index  = layer.load() ;
                E.ajax( {
                    type:'get',
                    url: '/lar/develop/function/store/'+func.function_id,
                    data: configure,
                    dataType:'json',

                    // 返回值判断
                    success: function ( obj ){

                        layer.close( index) ;

                        if ( obj.code == 200 ) {
                            layer.alert( obj.message , { icon: 1,time : 1500 } ) ;
                        } else {
                            layer.alert( obj.message , { icon: 2 } ) ;
                        }
                    }
                } ) ;

            }

        };

        function init() {
            //行拖动事件
            $("#sortable_tr").sortable({
                cursor: "move"
            });
        }

    </script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('develop.layoutEdit', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>